<template>
  <div id="search">
    <!-- 推荐热搜 -->
    <div class="top-searchGoods_item">
      <p class="title">热搜</p>
      <ul>
        <li>三只松鼠</li>
        <li>合味道</li>
        <li>康师傅</li>
        <li>啦啦啦</li>
        <li>啦啦啦啦啦</li>
      </ul>
    </div>
    <!-- 搜索结果 -->
    <div class="body-search_result">
      <p class="title">搜索结果</p>

      <!-- 赋值搜索结果 -->
      <ul>
        <li v-for="item in $store.getters.getCheckSearh" :key="item.id" @click="goGoodsDetails(item.id)">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {

    }
  },
  methods: {
    getAllGoodsInfo() {
      //获取数据库的商品信息
      this.$http.get(`http://172.20.10.4:5000/getGoodsInfo`).then(r => {
          let allGoods = r.body.data;
          //把所有数据放到store里了
          this.$store.commit("getAllGoodsInfo",allGoods);
      });
    },
    goGoodsDetails(id){
        this.$router.push(`/goodsdetails/${id}`)
    }
  },
  created(){
      this.getAllGoodsInfo();
  }
};
</script>
<style lang="less" scoped>
#search {
  padding-top: 1.3rem;
  .top-searchGoods_item {
    background-color: #fff;
    padding: 0.25rem 0;
    p.title {
      font-size: 0.3rem;
      color: #1e2625;
      margin-bottom: 0.2rem;
      font-weight: 700;
      padding-left: 0.25rem;
    }
    ul {
      width: 100%;
      display: flex;
      flex-direction: row;
      li {
        display: inline-block;
        padding: 0 0.1rem;
        font-size: 0.3rem;
        color: #5e6060;
        background-color: #f0f2f5;
        margin-left: 0.2rem;
        border-radius: 0.1rem;
        height: 0.5rem;
        line-height: 0.5rem;
      }
    }
  }
  .body-search_result {
    width: 100%;
    margin-top: 0.2rem;
    background-color: #fff;
    p.title {
      font-size: 0.3rem;
      color: #1e2625;
      font-weight: 700;
      padding-left: 0.25rem;
      padding-top: 0.25rem;
      padding-bottom: 0.25rem;
      margin-bottom: 0;
      border-bottom: 0.01rem solid #ccc;
    }
    ul {
      width: 100%;
      display: flex;
      flex-direction: column;
      li {
        width: 100%;
        height: 0.9rem;
        color: #5e6060;
        font-size: 0.3rem;
        line-height: 0.9rem;
        border-bottom: 0.01rem solid #ccc;
        padding-left: 0.25rem;
      }
    }
  }
}
</style>
